package com.bsj.pay.controller;

import com.bsj.pay.common.Result;
import com.bsj.pay.config.GlobalConfig;
import com.bsj.pay.controller.admin.UserController;
import com.bsj.pay.model.MerchantBean;
import com.bsj.pay.model.MessageBean;
import com.bsj.pay.model.OrderBean;
import com.bsj.pay.service.MerchantService;
import com.bsj.pay.service.MessageService;
import com.bsj.pay.service.OrderService;
import com.bsj.pay.util.HttpUtil;
import com.bsj.pay.util.QrCodeUtil;
import com.bsj.pay.util.date.DateTimeUtil;
import com.bsj.pay.util.http.Http;
import com.bsj.pay.util.http.Http.Response;
import com.bsj.pay.util.json.JSONUtil;
import com.bsj.pay.util.security.Base64;
import com.bsj.pay.util.security.MD5;
import com.bsj.pay.util.security.PassWrodsCreater;
import com.google.zxing.WriterException;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import net.sf.json.JSONObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


@Controller
@RequestMapping("/api/wechat")
public class WechatController {

	private static Logger log = LogManager.getLogger(WechatController.class);

	@Autowired
	private WxMpService wxMpService;

	@GetMapping("/getSignInfo")
	public Object authorize(@RequestParam("returnUrl") String returnUrl) throws WxErrorException {
		String url = "http://xx.natapp1.cc/shell/wechat/userInfo";
		WxJsapiSignature result = wxMpService.createJsapiSignature(returnUrl);
		return result;
	}
}
